package javabase.reflect;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class IntroSpectorTest {
	
	
	public static void main(String[] args) {

		Bean bean = new Bean(1L, "dek");
		
		PropertyDescriptor p;
		try {
			p = new PropertyDescriptor("id", bean.getClass());
			Method methodGet = p.getReadMethod();
			
			Object val = methodGet.invoke(bean);
			System.out.println(val);
			
			
			Method methodSet = p.getWriteMethod();
			
			methodSet.invoke(bean, 2L);
			
			System.out.println(bean.getId());
			
			BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass());
			PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
			for (PropertyDescriptor pd : pds) {
				if (pd.getName().equals("id")) {
					Method methodGetId = pd.getReadMethod();
				}
			}
			
		} catch (IntrospectionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		
		
	}
}
